home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevimgn.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  19.0 KB  |  572 lines

  1. /* Copyright (C) 1992, 1993, 1994, 1996 by Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevimgn.c,v 1.2 2000/09/19 19:00:13 lpd Exp $*/
  20. /*
  21.  * Imagen ImPRESS printer driver - version 1.4
  22.  *
  23.  * This driver uses the Impress bitmap operation to print the page image.
  24.  */
  25.  
  26. /* Written by Alan Millar (AMillar@bolis.sf-bay.org) August 4 1992.
  27.       Basic bitmap dump.  */
  28. /* Updated by Alan Millar Sept 21 1992.  Added resolution handling 
  29.       for 75, 150, and 300 dpi. */
  30. /* Updated by Alan Millar June 05 1993.  General cleanup for
  31.    beta test release. */
  32. /* Updated by Alan Millar June 21 1993.  v1.3.  Combined multipage
  33.    output into single imPress document.  Quote fewer special
  34.    chars in byte stream mode.  imPress document header options
  35.    can be set from environment variable IMPRESSHEADER */
  36. /* Updated by Alan Millar July 04 1993.  v1.4. 
  37.    New makefile option USE_BYTE_STREAM instead of changing source.
  38.    Swatch output redone to eliminate ALL blank swatches (swatchMap).
  39.    Buffer copying changed to multi-byte operations (BIGTYPE).
  40.    Page margins and A4 paper settings fixed, at least for Canon CX.
  41.    */
  42.  
  43. /* -------------------------------------------------------- */ 
  44. /* Instructions:  
  45.  
  46.    - Add "imagen.dev" to DEVICE_DEVS in the makefile.  For example:
  47.     DEVICE_DEVS2=laserjet.dev imagen.dev
  48.  
  49.    - Include or exclude USE_BYTE_STREAM in makefile as appropriate
  50.      If you are compiling on Unix, re-run "tar_cat" to update the makefile
  51.       from devs.mak
  52.  
  53.    - At run time, specify the resolution on the GS command line
  54.       by using -r300 or -r150 or -r75
  55.    - At run time, specify any imPress document options in
  56.       the IMPRESSHEADER environment variable.
  57.    */
  58.  
  59. /* -------------------------------------------------------- */
  60. /* Hardware/software combinations tested:
  61.    - ImageStation IP3 8/300 with parallel byte-stream interface,
  62.        using GS 2.6.1 on Linux with GCC 2.3.3;
  63.        earlier using GS 2.5.1 on MS-Dos with Turbo C++ 1.0
  64.    - Sequenced-packet-protocol interface untested.
  65.    */
  66. /* -------------------------------------------------------- */
  67. /* Bugs/Enhancements:
  68.    - Driver does not use any Impress language features for 
  69.      drawing lines/arcs
  70.    - Driver does not use resident or downloadable fonts.
  71.    - Buffer output instead of system call for each byte?
  72.   */
  73.  
  74. /* -------------------------------------------------------- */ 
  75. #include "gdevprn.h" 
  76. /* #include <stdio.h> should not be used in drivers */
  77. #include <stdlib.h>
  78.  
  79. /* -------------------------------------------------------- */ 
  80. /* Working Constants */
  81.  
  82. /* Byte stream quoting: convert special characters to hex.
  83.    Specify by including/excluding -DUSE_BYTE_STREAM in makefile.
  84.    This should match printer's hardware interface configuration.
  85.    If printer interface is serial with sequenced-packet-protocol 
  86.      spooler software (ImageStation config# 11 = 01), then don't use it.
  87.      Imagen "ipr" spooler software should not use byte stream.
  88.    If printer interface is Centronics parallel byte stream, 
  89.      (ImageStation config# 11 = 03), then use byte stream.  */
  90.  
  91. #ifdef USE_BYTE_STREAM
  92. #  define BYTE_STREAM 1
  93. #else
  94. #  define BYTE_STREAM 0
  95. #endif
  96.  
  97. /* Byte stream quote character (ImageStation config# 15).
  98.    Only needed when using byte stream */
  99. #define QUOTE_CHAR (char) 0x02
  100. /* Byte stream end-of-file character (ImageStation config# 14). */
  101. #define EOF_CHAR   (char) 0x04 
  102. /* Other special characters to quote.  Put them here if spooler or
  103.    hardware uses flow control, etc.   If not needed, set to
  104.    a redundant value such as EOF_CHAR */
  105. #define EXTRA_QUOTE1 (char) 0x11   /* ^Q */
  106. #define EXTRA_QUOTE2 (char) 0x13   /* ^S */
  107. #define EXTRA_QUOTE3 EOF_CHAR
  108. #define EXTRA_QUOTE4 EOF_CHAR
  109.  
  110. /* -------------------------------------------------------- */ 
  111. /* imPress header default options.  
  112.    Can be overridden at run-time with IMPRESSHEADER env variable */
  113.  
  114. #define IMPRESSHEADER "jobheader onerror, prerasterization off"
  115.  
  116. /* -------------------------------------------------------- */ 
  117.  
  118. #define CANON_CX
  119.  
  120. /* Printer engine max resolution.  300 for Canon CX models such as 
  121.    ImageStation IP3.  Others (240?) unverified */ 
  122. #ifdef CANON_CX
  123. #  define MAX_DPI 300 
  124. #endif
  125. #ifndef MAX_DPI
  126. #  define MAX_DPI 300 
  127. #endif
  128.  
  129. /* Determine imPress scaling factor from GS resolution.  
  130.    Magnify can be 0, 1, or 2. 
  131.     0 = MAX_DPI, 1 = MAX_DPI / 2, 2 = MAX_DPI / 4 
  132.    Assuming MAX_DPI is 300, you can specify -r75 or -r150
  133.     or -r300 on the GS command line  */ 
  134. #define getMagnification  ( \
  135.   ( pdev->x_pixels_per_inch > (MAX_DPI >> 1) ) ? 0 : \
  136.   ( pdev->x_pixels_per_inch > (MAX_DPI >> 2) ) ? 1 : \
  137.   2 )
  138.  
  139. /* Page dimensions from gdevprn.h - specify -DA4 in makefile for A4 paper */ 
  140. #define WIDTH_10THS   DEFAULT_WIDTH_10THS
  141. #define HEIGHT_10THS  DEFAULT_HEIGHT_10THS
  142.  
  143. /* Width in inches of unprintable edge of paper.  May need fine tuning.
  144.    Canon CX engine in ImageStation IP3 8/300 will only print 8 inches
  145.    wide on any paper size.  May vary for other engines */
  146.  
  147. #ifdef CANON_CX
  148. #  define MARG_L 0.15
  149. #  define MARG_R ( (float)WIDTH_10THS / 10.0 - 8.0 - MARG_L)
  150. #endif
  151. #ifndef MARG_L
  152. #  define MARG_L 0.2
  153. #endif
  154. #ifndef MARG_R
  155. #  define MARG_R 0.2
  156. #endif
  157. #define MARG_T 0.1 
  158. #define MARG_B 0.2 
  159.  
  160.  
  161. /* Flag for displaying debug messages at run-time.  Higher
  162.     number = higher detail */
  163. #define IM_DEBUG 0
  164. #define DebugMsg(Level,P1,P2) if (Level<=IM_DEBUG) {fprintf(stderr,P1,P2 );}
  165.  
  166. /*-------------------------------------------*/ 
  167.   /* Impress bitmaps are made up of 32x32 bit swatches. 
  168.      A swatch is four bytes (32 bits) wide by 32 bytes high,
  169.      totalling 128 bytes.  */
  170. #define HorzBytesPerSw 4
  171. #define HorzBitsPerSw (HorzBytesPerSw * 8)
  172. #define VertBytesPerSw 32
  173. #define TotalBytesPerSw (HorzBytesPerSw * VertBytesPerSw)
  174.  
  175. /*-------------------------------------------*/ 
  176. /* Attempt at optimization to something faster than byte-by-byte copying.  
  177.    imPress swatches are 4 bytes wide, so type must align on a 4-byte 
  178.    boundary.  Swatch interleaving restricts the copy to 4 bytes in a row.  
  179.    Type must be numeric where value is zero when all bytes in it are zero. */
  180. #if arch_sizeof_long == 4
  181. #  define BIGTYPE unsigned long int
  182. #else
  183. #  if arch_sizeof_short == 4
  184. #    define BIGTYPE unsigned short int
  185. #  else
  186. #    if arch_sizeof_short == 2
  187. #      define BIGTYPE unsigned short
  188. #    endif
  189. #  endif
  190. #endif
  191. #ifndef BIGTYPE
  192. #define BIGTYPE byte
  193. #endif
  194.  
  195. #define BIGSIZE ( sizeof( BIGTYPE ) )
  196.  
  197. /*-------------------------------------------*/ 
  198. /*    IMAGEN imPress Command opcodes                    */ 
  199. /* from DVIIMP.C */ 
  200. #define iSP        128    /* advance one space            */ 
  201. #define    iSP1        129    /* advance one space + 1 pixel        */ 
  202. #define iMPLUS        131    /* Move one pixel forward        */ 
  203. #define    iMMINUS        132    /* Move one pixel back            */ 
  204. #define iMMOVE        133    /* Move in main advance direction    */ 
  205. #define iSMOVE        134    /* Move in secondary advance direction    */ 
  206.  
  207. #define iABS_H        135    /* Move to H position            */ 
  208. #define iREL_H        136    /* Move in H direction            */ 
  209. #define iABS_V        137    /* Move to V position            */ 
  210. #define iREL_V        138    /* Move in V direction            */ 
  211.  
  212. #define    iCRLF        197    /* move to beginning of next line    */ 
  213.  
  214. #define    iSET_HV_SYSTEM    205    /* Define new coordinate system        */ 
  215. #define    iSET_ADV_DIRS    206    /* Define advance directions        */ 
  216.  
  217. #define    iPAGE        213    /* Set H and V to 0            */ 
  218. #define iENDPAGE    219    /* print the current page        */ 
  219.  
  220. #define iBITMAP        235    /* Print a full bitmap            */ 
  221. #define iSET_MAGNIFICATION 236 
  222.                 /* magnify the page by 1, 2, 4        */ 
  223. #define iNOOP        254    /* no operation                */ 
  224. #define iEOF        255    /* end of impress document        */ 
  225.  
  226. /*-------------------------------------------*/ 
  227. /*-------------------------------------------*/ 
  228. /* The device descriptor */ 
  229.  
  230. private dev_proc_print_page(imagen_print_page); 
  231. private dev_proc_open_device(imagen_prn_open);
  232. private dev_proc_close_device(imagen_prn_close);
  233.  
  234. gx_device_procs imagen_procs =
  235.     prn_procs(imagen_prn_open, gdev_prn_output_page, imagen_prn_close);
  236.  
  237. #define ppdev ((gx_device_printer *)pdev)
  238.  
  239. /*-------------------------------------------*/ 
  240. gx_device_printer far_data gs_imagen_device = 
  241.   prn_device(/*prn_std_procs*/ imagen_procs,
  242.     "imagen", 
  243.     WIDTH_10THS, 
  244.     HEIGHT_10THS, 
  245.     MAX_DPI,                /* x_dpi */ 
  246.     MAX_DPI,                /* y_dpi */ 
  247.     MARG_L,MARG_R,MARG_T,MARG_B,        /* margins */ 
  248.     1, imagen_print_page); 
  249.  
  250. /*-------------------------------------------*/ 
  251.  
  252. /*-------------------------------------------*/ 
  253. private void 
  254. iWrite(FILE *Out, byte Val) 
  255. { /* iWrite */ 
  256.   char *hexList = "0123456789ABCDEF"; 
  257.  
  258.   /* if we are doing byte-stream, quote characters that would otherwise
  259.      match EOF and QUOTE itself, or other special chars */
  260.   /* Imagen quoting takes one character and writes out the QUOTE
  261.      character followed by the hex digits of the quoted character */
  262.   if (BYTE_STREAM && 
  263.      (   Val == QUOTE_CHAR   || Val == EOF_CHAR
  264.       || Val == EXTRA_QUOTE1 || Val == EXTRA_QUOTE2
  265.       || Val == EXTRA_QUOTE3 || Val == EXTRA_QUOTE4 ) ) { 
  266.     fputc (QUOTE_CHAR, Out); 
  267.     fputc ((char) hexList[Val / 0x10], Out); 
  268.     fputc ((char) hexList[Val % 0x10], Out); 
  269.   } else { /* quoted char */ 
  270.     /* Not doing quoting, just send it out */
  271.     fputc(Val, Out); 
  272.   } /* quoted char */ 
  273. } /* iWrite */ 
  274.  
  275. /* Write out 16bit, high byte first */ 
  276. void 
  277. iWrite2(FILE *Out, int Val) 
  278. { /* iWrite2 */ 
  279.   iWrite(Out,(byte) (Val >> 8) & 0x00FF ); 
  280.   iWrite(Out,(byte) Val        & 0x00FF ); 
  281. } /* iWrite2 */ 
  282.  
  283. /* --------------------------------------------------------- */ 
  284.  
  285. private int
  286. imagen_prn_open(gx_device *pdev)
  287. { /* imagen_prn_open */
  288.   int    code;
  289.  
  290.   char *impHeader;
  291.  
  292.   /* ----------------------------------------- */
  293.   DebugMsg(1,"%s\n","Start of imagen_prn_open");
  294.   DebugMsg(2,"BIGSIZE = %ld \n",BIGSIZE);
  295.  
  296.   code = gdev_prn_open(pdev);
  297.   if ( code < 0 ) return code;
  298.  
  299.   /* ----------------------------------------- */
  300.  
  301.   DebugMsg(2,"opening file: %s\n",ppdev->fname);
  302.   code = gdev_prn_open_printer(pdev, 1);
  303.   if ( code < 0 ) return code;
  304.  
  305.   impHeader = getenv("IMPRESSHEADER");
  306.   if (impHeader == NULL ) {
  307.     impHeader = IMPRESSHEADER ;
  308.   } /* if impHeader */
  309.  
  310.   fprintf(ppdev->file,"@document(language impress, %s)",impHeader); 
  311.   
  312.   code = gdev_prn_close_printer(pdev);
  313.   if ( code < 0 ) return code;
  314.  
  315.   /* ----------------------------------------- */
  316.   DebugMsg(1,"%s\n","End of imagen_prn_open");
  317.  
  318.   return code;
  319. } /* imagen_prn_open */
  320.  
  321. private int
  322. imagen_prn_close(gx_device *pdev)
  323. { /* imagen_prn_close */
  324.   int        code;
  325.  
  326.   /* ----------------------------------------- */
  327.   DebugMsg(1,"%s\n","Start of imagen_prn_close");
  328.  
  329.   code = gdev_prn_open_printer(pdev, 1);
  330.   if ( code < 0 ) return code;
  331.  
  332.   /* Write imPress end of document marker */
  333.   iWrite(ppdev->file,iEOF); 
  334.  
  335.   /* And byte stream end of file */
  336.   if (BYTE_STREAM) { 
  337.     /* DON'T use iWrite because actual EOF should not be quoted! */
  338.     fputc(EOF_CHAR,ppdev->file); 
  339.   } /* if byte stream */ 
  340.  
  341.   fflush(ppdev->file);
  342.   
  343.   code = gdev_prn_close_printer(pdev);
  344.   if ( code < 0 ) return code;
  345.  
  346.   code = gdev_prn_close(pdev);
  347.  
  348.   DebugMsg(1,"%s\n","End of imagen_prn_close");
  349.  
  350.   return(code);
  351. } /* imagen_prn_close */
  352.  
  353. /*-------------------------------------------*/ 
  354. /* Send the page to the printer. */ 
  355. private int 
  356. imagen_print_page(gx_device_printer *pdev, FILE *prn_stream) 
  357.   int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev); 
  358.   /* input buffer: one line of bytes rasterized by gs */
  359.   byte *in = (byte *)gs_malloc(BIGSIZE, line_size / BIGSIZE + 1,
  360.     "imagen_print_page(in)"); 
  361.   /* output buffer: 32 lines, interleaved into imPress swatches */
  362.   byte *out; 
  363.   /* working pointer into output buffer */    
  364.   byte *swatch; 
  365.   byte *temp;
  366.   /* map of which swatches in a row are completely blank, or are non-blank */
  367.   byte *swatchMap;
  368.   /* starting line number on page of a row of swatches */
  369.   int lnum ; 
  370.   /* line number within a row of swatches */
  371.   int swatchLine; 
  372.   /* ending line number of row of swatches */
  373.   int lastLine; 
  374.   /* how many swatches can fit on a row */
  375.   int swatchCount; 
  376.   /* index into row of non-blank swatch */
  377.   int startSwatch; 
  378.   int endSwatch; 
  379.   /* Scaling factor for resolution */
  380.   int Magnify; 
  381.   /* page totals */
  382.   int totalBlankSwatches;
  383.   int totalGreySwatches;
  384.  
  385.   /* ----------------------------------------- */
  386.   /* Start of routine                          */
  387.   /* ----------------------------------------- */
  388.  
  389.   DebugMsg(1,"%s\n","Start of imagen_print_page");
  390.  
  391.   /* ----------------------------------------- */
  392.   Magnify = getMagnification ; 
  393.  
  394.   /* Impress bitmaps are made up of 32x32 bit swatches. 
  395.      A swatch is four bytes wide by 32 bytes high. 
  396.      See how many swatches will fit horizontally. */ 
  397.  
  398.   swatchCount = (line_size + HorzBytesPerSw - 1) / HorzBytesPerSw; 
  399.  
  400.   totalBlankSwatches = 0 ;
  401.   totalGreySwatches = 0 ;
  402.   DebugMsg(2,"Swatch count = %d\n",swatchCount);
  403.   DebugMsg(2,"Line size = %d\n",line_size );
  404.  
  405.   out = (byte *)gs_malloc(TotalBytesPerSw , swatchCount + 1, 
  406.             "imagen_print_page(out)"); 
  407.  
  408.   swatchMap = (byte *)gs_malloc(BIGSIZE,swatchCount / BIGSIZE + 1,
  409.     "imagen_print_page(swatchMap)" );
  410.  
  411.   if ( in == 0 || out == 0 ) 
  412.     return -1; 
  413.  
  414.   /* Initialize the page */ 
  415.   iWrite(prn_stream,iPAGE); 
  416.  
  417.   /* Tell ImPress what resolution we will be using */
  418.   iWrite(prn_stream,iSET_MAGNIFICATION); 
  419.       iWrite(prn_stream,Magnify); 
  420.  
  421.   /*------------------------------------------------------*/
  422.   /* main loop down page */ 
  423.   lnum = 0;
  424.   while (lnum <= pdev->height) { 
  425.  
  426.     /* erase swatch map.  */ 
  427.     for (swatch = swatchMap; swatch < swatchMap + swatchCount ; 
  428.         swatch += BIGSIZE ) { 
  429.       * (BIGTYPE *)swatch = (BIGTYPE) 0; 
  430.     } /* for  */ 
  431.  
  432.     /* get scan lines to fill swatches */ 
  433.     swatchLine = 0; 
  434.     lastLine = VertBytesPerSw - 1; 
  435.  
  436.     /* Check if we don't have a full-height row of swatches at end of page */
  437.     if (lnum + lastLine > pdev->height ) {
  438.       /* back up last row so it overlaps with previous.  Not a problem
  439.     on a laser printer, because the overlapping part will be identical */
  440.       lnum = pdev->height - lastLine ; 
  441.     }; /* not full height */
  442.  
  443.     DebugMsg (3,"lnum = %d \n",lnum);
  444.  
  445.     /* ------------------------------------------------------- */
  446.     /* get 32 lines and interleave into a row of swatches */ 
  447.     for (swatchLine = 0 ; swatchLine <= lastLine; swatchLine++) { 
  448.       /* blank out end of buffer for BIGSIZE overlap */
  449.       for (temp = in + line_size; temp < in + line_size + BIGSIZE;temp++){
  450.     *temp = 0;
  451.       } /* for temp */
  452.  
  453.       /* get one line */ 
  454.       gdev_prn_copy_scan_lines(pdev, lnum + swatchLine, in, line_size); 
  455.       DebugMsg(5,"Got scan line %d ", lnum + swatchLine);
  456.       DebugMsg(5,"line %d \n", swatchLine); 
  457.  
  458.       /* interleave scan line into swatch buffer */ 
  459.       /* a swatch is a 4 byte * 32 byte square.  Swatches are placed 
  460.      next to each other.  The first scan line maps into the first 
  461.      four bytes of the first swatch, then the first four of the second 
  462.      swatch, etc. 
  463.      To get this on the page: 
  464.        A1  A1  A1  A1  B1  B1  B1  B1  C1  C1  C1  C1 
  465.        A2  A2  A2  A2  B2  B2  B2  B2  C2  C2  C2  C2 
  466.        ... 
  467.        A32 A32 A32 A32 B32 B32 B32 B32 C32 C32 C32 C32 
  468.      You have to send it as: 
  469.        A1 A1 A1 A1 A2 ... A32 B1 B1 .. B32 C1 C1 ... C32   */ 
  470.  
  471.       /* set initial offset into swatch buffer based on which 
  472.      line in the swatch we are processing */ 
  473.       swatch = out + swatchLine * HorzBytesPerSw; 
  474.       DebugMsg(5,"offset: swatch = %d \n",(int) (swatch - out) );
  475.       temp = in; 
  476.       while ( temp < in + line_size ) { 
  477.     /* copy multi-byte to swatch buffer */ 
  478.     * (BIGTYPE *)swatch = * (BIGTYPE *)temp; 
  479.     if ( * (BIGTYPE *)temp ) {
  480.       /* mark map if not blank */
  481.       swatchMap[(swatch - out)/TotalBytesPerSw] = (byte) 1 ;
  482.     } /* if not zero */
  483.  
  484.     temp   += (BIGSIZE > HorzBytesPerSw) ? HorzBytesPerSw : BIGSIZE ; 
  485.     swatch += (BIGSIZE > HorzBytesPerSw) ? HorzBytesPerSw : BIGSIZE ; 
  486.  
  487.     /* if we copied four bytes, skip to next swatch */ 
  488.     if ( ((temp - in) % HorzBytesPerSw ) == 0 ) { 
  489.       swatch += (TotalBytesPerSw - HorzBytesPerSw) ; 
  490.     } /* if need to skip */
  491.       } /* while < line_size */ 
  492.  
  493.     } /* for swatchLine */ 
  494.  
  495.     /* ------------------------------------------------- */
  496.     /* we now have full swatches. */ 
  497.     /* Send to printer */ 
  498.  
  499.     /* go through swatch map to find non-blank swatches.
  500.        Skip over completely blank swatches */ 
  501.     startSwatch = 0;
  502.     while (startSwatch < swatchCount ) {
  503.       if (swatchMap[startSwatch] == 0 ) {
  504.     /* skip blank swatch */
  505.     DebugMsg(6,"Skip blank %d \n",startSwatch);
  506.     totalBlankSwatches++;
  507.     startSwatch++;
  508.       } else { /* if swatch == 0 */
  509.     /* we hit a non-blank swatch. */
  510.     totalGreySwatches++;
  511.  
  512.     /* See how many there are in a row */
  513.     endSwatch = startSwatch;
  514.     while ( (endSwatch < swatchCount) && swatchMap[endSwatch] ) {
  515.       endSwatch++;
  516.       totalGreySwatches++;
  517.     } /* while */
  518.     /* endSwatch is one past last non-blank swatch */
  519.     DebugMsg(6,"Grey swatches %d ",startSwatch);
  520.     DebugMsg(6,"until %d \n",endSwatch);
  521.  
  522.     /* vertical position: scan line, shifted for magnification */ 
  523.     iWrite(prn_stream, iABS_V); 
  524.       iWrite2(prn_stream, lnum << Magnify); 
  525.  
  526.     /* horizontal position = swatch number * 32 bits/swatch */ 
  527.     iWrite(prn_stream,iABS_H); 
  528.        iWrite2(prn_stream, startSwatch * HorzBitsPerSw << Magnify ); 
  529.     iWrite(prn_stream,iBITMAP);  /* start bitmap */ 
  530.       iWrite(prn_stream,0x07);     /* bit OR with page */ 
  531.       iWrite(prn_stream,(endSwatch - startSwatch)); /* horizontal 
  532.         number of swatches */ 
  533.       iWrite(prn_stream, 1) ; /* vertical number of swatches */ 
  534.     /* write out swatch buffer */ 
  535.     for (swatch = out + startSwatch * TotalBytesPerSw;
  536.         swatch < out + endSwatch * TotalBytesPerSw; swatch++) { 
  537.       iWrite(prn_stream,*swatch); 
  538.     } /* for swatch */ 
  539.  
  540.     /* swatches have been printed, see if there are still
  541.        more in this row */
  542.     startSwatch = endSwatch;
  543.       } /* if swatch == 0 */
  544.  
  545.     } /* while startSwatch */
  546.    
  547.     /* Whole row of swatches is done.  Go on to next row of swatches */
  548.     lnum += lastLine + 1; 
  549.  
  550.   } /* while lnum */ 
  551.  
  552.   /* Eject the page */ 
  553.   iWrite(prn_stream,iENDPAGE); 
  554.  
  555.   fflush(prn_stream); 
  556.  
  557.   gs_free((char *)swatchMap, BIGSIZE, swatchCount / BIGSIZE + 1,
  558.     "imagen_print_page(swatchMap)" );
  559.   gs_free((char *)out, TotalBytesPerSw, swatchCount+1, "imagen_print_page(out)"); 
  560.   gs_free((char *)in, BIGSIZE, line_size / BIGSIZE + 1, "imagen_print_page(in)"); 
  561.   /* ----------------------------------------- */
  562.  
  563.   DebugMsg(1,"Debug: Grey: %d \n",totalGreySwatches);
  564.   DebugMsg(1,"Debug: Blank: %d \n",totalBlankSwatches );
  565.   DebugMsg(1,"%s\n","End of imagen_print_page");
  566.  
  567.   /* ----------------------------------------- */
  568.   return 0; 
  569.  
  570. } /* imagen_print_page */ 
  571.